import 'package:flutter/material.dart';
import 'package:get/get.dart';

buildSelectList(
    {required List data,
    required String type,
    String title = "",
    bool hasBranch = false,
    Function? submitClickFn,
    Function? titleSlot,
    Function? iconSlot,
    Function? itemClickFn}) {
  var statusTopHeight = MediaQuery.of(Get.context!).padding.top;
  var statusBottomHeight = MediaQuery.of(Get.context!).padding.bottom;
  Get.bottomSheet(
      Container(
          decoration: const BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.only(
                topLeft: Radius.circular(20.0),
                topRight: Radius.circular(20.0)), //圆角
          ),
          child: Column(
            children: [
              SizedBox(
                width: double.infinity,
                height: statusTopHeight,
                // color: Colors.yellow,
              ),
              SizedBox(
                width: double.infinity,
                height: 60,
                // color: Colors.blue,
                child: Row(
                  children: [
                    GestureDetector(
                      onTap: () => {Get.back()},
                      child: Container(
                        alignment: Alignment.center,
                        width: 70,
                        height: double.infinity,
                        // color: Colors.red,
                        child: const Icon(
                          Icons.chevron_left_outlined,
                          size: 25,
                        ),
                      ),
                    ),
                    Expanded(
                        flex: 1,
                        child: Container(
                          alignment: Alignment.center,
                          width: double.infinity,
                          height: double.infinity,
                          // color: Colors.teal,
                          child: Text(
                            title,
                            style: const TextStyle(fontSize: 18),
                          ),
                        )),
                    GestureDetector(
                      onTap: () => {
                        if (hasBranch && submitClickFn != null)
                          {submitClickFn()}
                      },
                      child: Container(
                          alignment: Alignment.center,
                          width: 70,
                          height: double.infinity,
                          child: Visibility(
                              visible: hasBranch,
                              child: SizedBox(
                                width: double.infinity,
                                height: double.infinity,
                                child: Padding(
                                  padding: const EdgeInsets.only(
                                      right: 10, top: 8, bottom: 8),
                                  child: Container(
                                    width: double.infinity,
                                    height: double.infinity,
                                    alignment: Alignment.center,
                                    decoration: const BoxDecoration(
                                      color: Color(0xff4091F7),
                                      borderRadius: const BorderRadius.all(
                                          const Radius.circular(10.0)),
                                    ),
                                    child: const Text(
                                      "确定",
                                      style: TextStyle(
                                          fontSize: 16, color: Colors.white),
                                    ),
                                  ),
                                ),
                              ))),
                    )
                  ],
                ),
              ),
              Expanded(
                  flex: 1,
                  child: SizedBox(
                      width: double.infinity,
                      height: double.infinity,
                      child: SingleChildScrollView(
                        child: Column(
                            children: data.asMap().keys.map((index) {
                          return GestureDetector(
                              onTap: () {
                                if (itemClickFn != null) {
                                  // 抛出方法
                                  itemClickFn(data[index]["cardNo"].toString(),
                                      index, data[index]);
                                }
                              },
                              child: Container(
                                width: double.infinity,
                                height: 60,
                                decoration: const BoxDecoration(
                                  color: Colors.transparent,
                                  border: Border(
                                      top: BorderSide(
                                          width: 1.0, color: Color(0xffF4F4F4)),
                                      bottom: BorderSide(
                                          width: 1.0,
                                          color: Color(0xffF4F4F4))),

                                  // border: new Border.all(width: 2.0, color: Colors.red), //边框
                                ),
                                child: Row(
                                  children: [
                                    Expanded(
                                        flex: 1,
                                        child: Container(
                                            alignment: Alignment.centerLeft,
                                            width: double.infinity,
                                            height: double.infinity,
                                            padding: const EdgeInsets.only(
                                                left: 15, right: 15),
                                            child: Row(
                                              children: [
                                                if (titleSlot != null)
                                                  titleSlot(index)
                                                else
                                                  Text(data[index]["bankName"])
                                              ],
                                            ))),
                                    SizedBox(
                                        width: 60,
                                        height: double.infinity,
                                        // color: Colors.yellow,
                                        child: Column(
                                          mainAxisAlignment:
                                              MainAxisAlignment.center,
                                          children: [
                                            if (iconSlot != null)
                                              iconSlot(index)
                                            else
                                              const SizedBox(
                                                width: 25,
                                                height: 25,
                                              )
                                          ],
                                        ))
                                  ],
                                ),
                              ));
                        }).toList()),
                      ))),
              Container(
                width: double.infinity,
                height: statusBottomHeight,
                color: Colors.transparent,
              )
            ],
          )),
      isScrollControlled: true,
      // barrierColor: Colors.red,
      ignoreSafeArea: false,
      useRootNavigator: true);
}
